module namespace header="http://sendmeafilter.com/common/header";
import module namespace security="http://sendmeafilter.com/common/security" at "security.xqy";

declare boundary-space preserve;
declare option xdmp:mapping "false";

declare function header:prefer($one,$two) { if(fn:exists($one)) then $one else $two };
declare function header:create($name,$default,$meta) {
	<meta name="{$name}" content="{header:prefer(fn:data($meta[@name=$name]/@value),$default)}"/>
};
declare function header:option($name,$meta) { fn:data(($meta[@name=$name]/@value)[1]) }; 

declare function header:header($meta) {
(
	<!-- site header -->,
	<div id="header">
		<div id="top-header">
			<div class="wrapper">
				<div id="contact">
					<h4>Contact Us:  <a href="mailto:sendmeafilter@gmail.com">sendmeafilter@gmail.com</a></h4>
				</div>
			</div>
		</div>
		<div id="main-header">
			<div class="wrapper">
				<div id="logo">
					<h1>
						<a href="/" id="logo">SendMeAFilter</a>
					</h1>
				</div>
				{
					let $loggedIn := fn:not(security:user() = '_smaf_public')
					let $userName := security:userName()
					return 
						<ul id="site-nav">
							{ if($loggedIn) then 	
								<li class="current  index"><span class="myname">Hi, {$userName}</span></li> 
							else () }
								<li class="about-us"><a href="/aboutus" title="About Us">About Us</a></li>
								<li class="contact-us"><a href="/contactus" title="Contact Us">Contact Us</a></li>
							{ if(security:allowed('_smaf_backoffice')) then 	
								<li class="current  index"><a href="/backoffice" title="">BackOffice</a></li>
							else () }
							{ if($loggedIn) then 	
								<li class="current  index"><a href="/backoffice/logout" title="">Logout</a></li>
							else () }
						</ul>
			}
			</div>
		</div>
	</div>		
)
};

declare function header:doctype() {
let $type:=xdmp:set-response-content-type("text/html")
return
'<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->'
};

